/*
 * =====================================================================================
 *
 *       Filename:  physicshandler.h
 *
 *          Company: Awaaz.me
 *        Version:  1.0
 *        Created:  Monday 22 November 2010 08:04:51  IST
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  shashank singh
 *        Company:  a class to handle all our physics interactions :)
 *
 * =====================================================================================
 */

#ifndef PHYSICSHANDLER_H
#define PHYSICSHANDLER_H

#include <Box2D/Box2D.h>
#include <QTimer>
#include <QVector>
#include <QDebug>
#include <QGraphicsItem>

class _body //all defination for a body defined in one
{
public:
QList <QGraphicsItem*>item;
QList <b2Body*> elmentsInScene;
QList <b2BodyDef*>definationOfElements;
QList <b2PolygonShape*>shapeOfElements;
};
 

class physicsHandler :public QObject
{
Q_OBJECT
public:
physicsHandler();
~physicsHandler();
int convertToScreenResolution(float32);
float32 convertFromScreenResolution(int);

public slots:
void simulate();
void addBody();
signals :
void move(int,int);//emit how much the element should be moved by

private:
b2Vec2 *gravity;
bool doSleep;
b2World *world;
b2BodyDef *groundBodyDef;
b2Body* groundBody;
b2PolygonShape *groundBox;
b2BodyDef *bodyDef;//make a QVector out of this one
b2Body *body;//pointer to the body
b2PolygonShape *dynamicBox; //dynamic box to contain the body
b2FixtureDef *fixtureDef;//fixtures of the body
float32 timeStep;//time step of simulation
int32 velocityIterations;//velocity iteration
int32 positionIterations;//position iteration
float32 conversionRatioFromScreenTobox2d;
int conversionRatioFrombox2dToScreen;//ratio to be multiplied to all   ,to keep pixels and physics in sync/scale
_body bodyDefs;
};


#endif
